haskell

您所在的位置:网站首页 binding signature haskell

haskell

2024-02-17 14:18| 来源: 网络整理| 查看: 265

I have been googling around to find the answer, and even came to a few questions asked here. It seems that this is an ambiguous error and I can't figure out how to solve it in my instance.

The offending code is below:

pos :: (Eq a) => [a] -> a -> Int pos [] _ = -1 pos (x:xs) y | not $ elem y (x:xs) = -1 | x == y = 0 | otherwise = 1 + pos xs y -- Get the same element from another range as one element of the first range. refPos :: (Eq a) => [a] -> [b] -> a -> b refPos r1 r2 e1 = r2 !! (r1 `pos` e1) letterNumber :: (Eq a, Char a) => a -> Int lettNumber x = refPos ['a'..'z'] [0..25] x

The text of the exact error is:

15:1 The type signature for letterNumber lacks an accompanying binding.

Originally the type signature I put was Char -> Int, but that didn't work (it said something about Eq, but I'm too new too Haskell to interpret it properly). So I changed the type signature to have an Eq class constraint. If someone can point out what is wrong or a workaround, it would be greatly appreciated as this is a doorstop problem to a project I'm working on.



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3